<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>监护大纲-等级判定</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/layui/css/layui.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/admin.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/style.css"
      media="all"
    />
    <style>
      .guardianshipProgramTable {
        width: 100%;
      }

      .guardianshipProgramForm .layui-form-radio {
        margin: 0;
        padding: 0;
      }

      .layui-table th,
      .layui-table td,
      .layui-table-cell {
        height: 10px;
        line-height: 10px;
        min-height: 10px;
        font-size: 14px;
      }

      .layui-table th {
        font-weight: bolder;
        font-size: 14px;
      }

      .layui-textarea {
        resize: none;
      }

      .itemMargin {
        margin: 4px 0;
      }

      input[type="checkbox"i] {
        vertical-align: middle;
      }

      .layui-table tbody tr:hover {
        background-color: transparent;
      }

      .levelBox th {
        text-align: center;
      }

      .levelBox img {
        width: 30px;
        margin: 0 auto 5px;
        display: block;
      }
    </style>
  </head>

  <body>
    <div class="layui-fluid">
      <div style="height: 60px">
        <img
          src="../../layuiadmin/images/backPage.png"
          class="backPreviousPage"
        />
      </div>
      <form
        id="guardianshipProgramForm"
        class="guardianshipProgramForm layui-form"
        lay-filter="guardianshipProgramForm"
        action=""
      >
        <table class="layui-table">
          <tbody>
            <tr>
              <th class="title xrequired">项目类别：</th>
              <td colspan="2">
                <!-- <span style="color: red">* </span> -->
                <input
                  type="radio"
                  name="projectType"
                  value="1"
                  lay-filter="projectTypeConditions"
                  lay-verify="otherReq"
                />基坑工程
                <input
                  type="radio"
                  name="projectType"
                  value="2"
                  lay-filter="projectTypeConditions"
                  lay-verify="otherReq"
                />穿越工程
                <input
                  type="radio"
                  name="projectType"
                  value="3"
                  lay-filter="projectTypeConditions"
                  lay-verify="otherReq"
                />加卸载、管线、桥梁、桩基及其他类
              </td>
            </tr>
            <tr>
              <th colspan="5">轨道交通结构类型</th>
            </tr>
            <tr>
              <th class="title xrequired">线路情况：</th>
              <td colspan="2">
                <input
                  type="checkbox"
                  name="lineType"
                  lay-skin="primary"
                  value="1"
                  lay-filter="lineConditions"
                  lay-verify="otherReq"
                />运营
                <input
                  type="checkbox"
                  name="lineType"
                  lay-skin="primary"
                  value="2"
                  lay-filter="lineConditions"
                  lay-verify="otherReq"
                />在建
                <input
                  type="checkbox"
                  name="lineType"
                  lay-skin="primary"
                  value="3"
                  lay-filter="lineConditions"
                  lay-verify="otherReq"
                />规划
              </td>
            </tr>
            <tr>
              <th class="title xrequired">车站：</th>
              <td colspan="2">
                <input
                  type="checkbox"
                  name="stationFlag"
                  lay-skin="primary"
                  value="1"
                  lay-verify="otherReq"
                  lay-filter="stationConditions"
                />地上
                <input
                  type="checkbox"
                  name="stationFlag"
                  lay-skin="primary"
                  value="2"
                  lay-verify="otherReq"
                  lay-filter="stationConditions"
                />地下
              </td>
            </tr>
            <tr>
              <th class="title xrequired">区间：</th>
              <td colspan="2">
                <input
                  type="checkbox"
                  name="stationArea"
                  lay-skin="primary"
                  value="1"
                  lay-verify="otherReq"
                  lay-filter="stationAreaConditions"
                />单圆
                <input
                  type="checkbox"
                  name="stationArea"
                  lay-skin="primary"
                  value="2"
                  lay-verify="otherReq"
                  lay-filter="stationAreaConditions"
                />双圆
                <input
                  type="checkbox"
                  name="stationArea"
                  lay-skin="primary"
                  value="3"
                  lay-verify="otherReq"
                  lay-filter="stationAreaConditions"
                />矩形
                <input
                  type="checkbox"
                  name="stationArea"
                  lay-skin="primary"
                  value="4"
                  lay-verify="otherReq"
                  lay-filter="stationAreaConditions"
                />高架
                <input
                  type="checkbox"
                  name="stationArea"
                  lay-skin="primary"
                  value="5"
                  lay-verify="otherReq"
                  lay-filter="stationAreaConditions"
                />地面
              </td>
            </tr>
          </tbody>
        </table>
        <div class="tableList"></div>
        <table class="layui-table">
          <tbody>
            <tr>
              <th>其他判断</th>
              <th>判断</th>
            </tr>
            <tr>
              <td>该基坑项目开挖面积不足4H2,是否降低一级监护等级</td>
              <td>
                <input
                  type="checkbox"
                  lay-skin="primary"
                  name="soilMonitor"
                  value="1"
                />
              </td>
            </tr>
            <tr>
              <td>
                该项目地铁侧边长超过100m或者开挖面积超过1000m2的基坑,是否可提高一级监护等级
              </td>
              <td>
                <input
                  type="checkbox"
                  lay-skin="primary"
                  name="soilMonitor"
                  value="-1"
                />
              </td>
            </tr>
            <tr>
              <td>
                该项目为地铁结构特殊区段(旁通道、引导段等)、结构存在缺陷、使用状况恶化区段以及地址条件复杂的监护项目,是否提高一级监护等级:
              </td>
              <td>
                <input
                  type="checkbox"
                  lay-skin="primary"
                  name="soilMonitor"
                  value="-1"
                />
              </td>
            </tr>
            <tr>
              <td>该项目为涉及降承压水项目，是否提高一级监护等级:</td>
              <td>
                <input
                  type="checkbox"
                  lay-skin="primary"
                  name="soilMonitor"
                  value="-1"
                />
              </td>
            </tr>
          </tbody>
        </table>
        <table class="layui-table levelBox">
          <tbody>
            <tr>
              <th>监护等级</th>
              <th>
                <input type="radio" name="level" value="1" />特级
                <input type="radio" name="level" value="2" />一级
                <input type="radio" name="level" value="3" />二级
                <input type="radio" name="level" value="4" />三级
              </th>
              <th class="gradeCalculation">
                <button
                  type="button"
                  lay-submit
                  lay-filter="gradeCalculationSubmit"
                >
                  <img src="../../layuiadmin/images/refreshIcon.png" /><span
                    >等级计算</span
                  >
                </button>
              </th>
            </tr>
          </tbody>
        </table>
        <div style="text-align: center">
          <a href="javascript:;" class="gradeDeterminationSubmitHref">
            <button
              type="button"
              class="layui-btn gradeDeterminationSubmit"
              lay-submit
              lay-filter="gradeDeterminationSubmit"
            >
              确定
            </button>
          </a>
        </div>
      </form>
    </div>
    <script src="../../layuiadmin/modules/const_config.js"></script>
    <script src="../../layuiadmin/modules/jTools.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
      console.log(window, window.frameElement);
      layui
        .config({
          base: "../../layuiadmin/", //静态资源所在路径
          version: "20210514",
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["index", "contlist", "table"], function () {
          var table = layui.table,
            $ = layui.$,
            form = layui.form;
          var no = jTools.getQuery("no");
          var uuid = layui.data("uuid").key;
          var datas = [];
          //  去重
          function unique(arr) {
            return arr.filter(function (item, index, arr) {
              //当前元素，在原始数组中的第一个索引==当前索引值，否则返回当前元素
              return arr.indexOf(item, 0) === index;
            });
          }
          //自定义验证规则
          form.verify({
            otherReq: function (value, item) {
              var $ = layui.$;
              var verifyName = $(item).attr("name"),
                verifyType = $(item).attr("type"),
                formElem = $(item).parents(".layui-form"), //获取当前所在的form元素，如果存在的话
                verifyElem = formElem.find("input[name=" + verifyName + "]"), //获取需要校验的元素
                isTrue = verifyElem.is(":checked"), //是否命中校验
                focusElem = verifyElem.next().find("i.layui-icon"); //焦点元素
              if (!isTrue || !value) {
                //定位焦点
                focusElem.css(
                  verifyType == "radio"
                    ? { color: "#FF5722" }
                    : { "border-color": "#FF5722" }
                );
                //对非输入框设置焦点
                focusElem
                  .first()
                  .attr("tabIndex", "1")
                  .css("outline", "0")
                  .blur(function () {
                    focusElem.css(
                      verifyType == "radio"
                        ? { color: "" }
                        : { "border-color": "" }
                    );
                  })
                  .focus();
                return "必填项不能为空";
              }
            },
          });

          $(
            '#LAY-system-side-menu dd[data-name="technicalRequirement"]',
            parent.document
          ).removeClass("layui-this");

          $.ajax({
            type: "post",
            async: false, //异步执行
            url: base_url + "/outlineProjects/projectInfo/" + uuid,
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            success: function (data) {
              if (data.code == 200) {
                var data = data.data;

                form.on("radio(projectTypeConditions)", function (data) {
                  projectTypeCheckFun(data.value);
                });

                function checkBoxFun(checkBoxArray, data) {
                  checkBoxArray.each(function (index, item) {
                    for (v in data) {
                      if (item.value == data[v]) {
                        item.checked = true;
                      }
                    }
                  });
                  form.render();
                }
                if (data.hasOwnProperty("projectType")) {
                  projectTypeCheckFun(data.projectType);
                  var projectTypeCheckBox = $("input[name='projectType']");
                  var projectTypeData = data.projectType.split(",");
                  checkBoxFun(projectTypeCheckBox, projectTypeData);
                }
                if (data.hasOwnProperty("lineType")) {
                  var lineTypeCheckBox = $("input[name='lineType']");
                  var lineTypeData = data.lineType.split(",");
                  checkBoxFun(lineTypeCheckBox, lineTypeData);
                }
                if (data.hasOwnProperty("stationFlag")) {
                  var stationFlagCheckBox = $("input[name='stationFlag']");
                  var stationFlagData = data.stationFlag.split(",");
                  checkBoxFun(stationFlagCheckBox, stationFlagData);
                }
                if (data.hasOwnProperty("stationArea")) {
                  var stationAreaCheckBox = $("input[name='stationArea']");
                  var stationAreaData = data.stationArea.split(",");
                  checkBoxFun(stationAreaCheckBox, stationAreaData);
                }
              }
            },
          });
          function projectTypeCheckFun(projectType) {
            $.ajax({
              type: "post",
              async: false, //异步执行
              url:
                base_url + "/outlineProjects/parse/" + uuid + "/" + projectType,
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              success: function (data) {
                if (data.code == 200) {
                  var dataConfig = data.data;
                  datas = dataConfig;
                  $(".tableList").empty();
                  for (var i in dataConfig) {
                    var tablelist = "";
                    tablelist +=
                      '<table class="layui-table "><tbody><tr><th colspan=4>' +
                      i +
                      "</th></tr>";
                    tablelist +=
                      "<tr><td>数据名称</td><td>数据符号</td><td>具体数值</td><td>备注</td></tr>";
                    for (var j = 0; j < dataConfig[i].length; j++) {
                      tablelist +=
                        '<tr><td style="width:40%">' +
                        dataConfig[i][j].name +
                        '</td><td style="width:10%">' +
                        dataConfig[i][j].symbol +
                        '</td><td style="width:10%"><input type="text" id="' +
                        i +
                        dataConfig[i][j].field +
                        '" value="' +
                        dataConfig[i][j].value +
                        '"></td><td style="width:40%">' +
                        dataConfig[i][j].note +
                        "</td></tr>";
                    }
                    tablelist += "</tbody></table>";
                    $(".tableList").append(tablelist);
                  }
                }
              },
            });
          }

          // $.ajax({
          //   type: "post",
          //   async: false, //异步执行
          //   url: base_url + "/outlineProjects/parse/" + uuid,
          //   headers: {
          //     Accept: "application/json; charset=utf-8",
          //     Authorization: layui.sessionData("userToken").key,
          //   },
          //   // data: { projectType: 3 },
          //   success: function (data) {
          //     data = data.data;
          //     datas = data.config;
          //     console.log(datas);
          //     var projectTypeCheckBox = $("input[name='projectType']");
          //     var projectTypeData = data.projectInfo.projectType;
          //     checkBoxFun(projectTypeCheckBox, projectTypeData);

          //     // var lineTypeCheckBox = $("input[name='lineType']");
          //     // var lineTypeData = data.projectInfo.lineType;
          //     // checkBoxFun(lineTypeCheckBox, lineTypeData);

          //     // var stationFlagCheckBox = $("input[name='stationFlag']");
          //     // var stationFlagData = data.projectInfo.stationFlag;
          //     // checkBoxFun(stationFlagCheckBox, stationFlagData);

          //     // var stationAreaCheckBox = $("input[name='stationArea']");
          //     // var stationAreaData = data.projectInfo.stationArea;
          //     // checkBoxFun(stationAreaCheckBox, stationAreaData);
          //     var lineTypeData = data.projectInfo.lineType;
          //     if (lineTypeData.length == 1) {
          //       lineTypeArray = lineTypeData;
          //     } else {
          //       lineTypeArray = lineTypeData.split(",");
          //     }
          //     var lineTypeCheckBox = $("input[name='lineType']");
          //     checkBoxFunction(lineTypeCheckBox, lineTypeArray);

          //     var stationFlagData = data.projectInfo.stationFlag;
          //     if (stationFlagData.length == 1) {
          //       stationFlagArray = stationFlagData;
          //     } else {
          //       stationFlagArray = stationFlagData.split(",");
          //     }
          //     var stationFlagCheckBox = $("input[name='stationFlag']");
          //     checkBoxFunction(stationFlagCheckBox, stationFlagArray);

          //     if (data.projectInfo.hasOwnProperty("stationArea")) {
          //       var stationAreaData = data.projectInfo.stationArea;

          //       if (stationAreaData.length == 1) {
          //         stationAreaArray = stationAreaData;
          //       } else {
          //         stationAreaArray = stationAreaData.split(",");
          //       }
          //       var stationAreaCheckBox = $("input[name='stationArea']");
          //       checkBoxFunction(stationAreaCheckBox, stationAreaArray);
          //     }

          //     function checkBoxFunction(checkboxData, checkBoxArray) {
          //       for (var i = 0; i < checkBoxArray.length; i++) {
          //         for (var j = 0; j < checkboxData.length; j++) {
          //           var checkbox = $(checkboxData[j]);
          //           if (checkbox.val() == checkBoxArray[i]) {
          //             checkbox.attr("checked", "checked");
          //             break;
          //           }
          //         }
          //       }
          //     }

          //     form.render("checkbox");

          //     function checkBoxFun(checkBoxArray, data) {
          //       checkBoxArray.each(function (index, item) {
          //         if (item.value == data) {
          //           item.checked = true;
          //         } else if (data === 3) {
          //           item.checked = true;
          //         }
          //       });
          //     }
          //     form.render();

          //     // var tablelist = "";
          //     // for (var i in data.config) {
          //     //   // debugger;
          //     //   // if (i == "加卸" || i == "卸载") {
          //     //   //   debugger;
          //     //   //   greenProject = 1;
          //     //   // }
          //     //   tablelist +=
          //     //     '<table class="layui-table"><tbody><tr><th colspan=4>' +
          //     //     i +
          //     //     "</th></tr>";
          //     //   tablelist +=
          //     //     "<tr><td>数据名称</td><td>数据符号</td><td>具体数值</td><td>备注</td></tr>";
          //     //   for (var j = 0; j < data.config[i].length; j++) {
          //     //     tablelist +=
          //     //       '<tr><td style="width:40%">' +
          //     //       data.config[i][j].name +
          //     //       '</td><td style="width:10%">' +
          //     //       data.config[i][j].symbol +
          //     //       '</td><td style="width:10%"><input type="text" id="' +
          //     //       i +
          //     //       data.config[i][j].field +
          //     //       '" value="' +
          //     //       data.config[i][j].value +
          //     //       '"></td><td style="width:40%">' +
          //     //       data.config[i][j].note +
          //     //       "</td></tr>";
          //     //   }
          //     //   tablelist += "</tbody></table>";
          //     //   $(".tableList").append(tablelist);
          //     //   tablelist = "";
          //     // }
          //   },
          // });

          // form.on("checkbox(lineConditions)", function (data) {
          //   console.log(data.elem.checked);
          //   if (data.value == 2 && data.elem.checked == true) {
          //     layer.confirm("在建地铁结构是否已经完成", {
          //       icon: 1,
          //       btn: ["是", "否"],
          //       yes: function () {
          //         layer.closeAll();
          //         // gradeCalculationFun();
          //       },
          //       btn2: function () {
          //         layer.closeAll();
          //         $("input[name='level']").each(function (index, item) {
          //           if (item.value == 3) {
          //             item.checked = true;
          //             form.render();
          //           }
          //         });
          //       },
          //     });
          //   }
          // });
          var levelData = "";
          var dataF = "";
          var greenProject = 0;
          // 多选赋值
          let lineArr = [],
            flagArr = [],
            areaArr = [],
            lineValue = "",
            flagValue = "",
            areaValue = "";
          let lineType = $("input[name='lineType']").get();
          let stationFlag = $("input[name='stationFlag']").get();
          let stationArea = $("input[name='stationArea']").get();
          lineType.forEach((val) => {
            if (val.checked) {
              lineArr.push(val.value);
            }
          });
          form.on("checkbox(lineConditions)", function (data) {
            if (data.elem.checked) {
              lineArr.push(data.value);
              if (data.value == 2 && data.elem.checked == true) {
                layer.confirm("在建地铁结构是否已经完成", {
                  icon: 1,
                  btn: ["是", "否"],
                  yes: function () {
                    layer.closeAll();
                    // gradeCalculationFun();
                  },
                  btn2: function () {
                    layer.closeAll();
                    $("input[name='level']").each(function (index, item) {
                      if (item.value == 3) {
                        item.checked = true;
                        form.render();
                      }
                    });
                  },
                });
              }
            } else {
              lineArr.splice($.inArray(data.value, lineArr), 1);
            }
            lineValue = unique(lineArr).join(",");
            console.log(lineValue);
          });

          stationFlag.forEach((val) => {
            if (val.checked) {
              flagArr.push(val.value);
            }
          });
          form.on("checkbox(stationConditions)", function (data) {
            if (data.elem.checked) {
              flagArr.push(data.value);
            } else {
              flagArr.splice($.inArray(data.value, flagArr), 1);
            }
            flagValue = unique(flagArr).join(",");
            console.log(flagValue);
          });

          stationArea.forEach((val) => {
            if (val.checked) {
              areaArr.push(val.value);
            }
          });
          form.on("checkbox(stationAreaConditions)", function (data) {
            if (data.elem.checked) {
              areaArr.push(data.value);
            } else {
              areaArr.splice($.inArray(data.value, areaArr), 1);
            }
            areaValue = unique(areaArr).join(",");
            console.log(areaValue);
          });
          function getCheck() {
            var lineTypeCheckBox = $("input[name='lineType']");
            lineTypeCheckBox.each(function (index, item) {
              if (item.checked == true) {
                lineArr.push(item.value);
              }
              lineValue = unique(lineArr).join(",");
            });

            var stationFlagCheckBox = $("input[name='stationFlag']");
            stationFlagCheckBox.each(function (index, item) {
              if (item.checked == true) {
                flagArr.push(item.value);
              }
              flagValue = unique(flagArr).join(",");
            });
            var stationAreaCheckBox = $("input[name='stationArea']");
            stationAreaCheckBox.each(function (index, item) {
              if (item.checked == true) {
                areaArr.push(item.value);
              }
              areaValue = unique(areaArr).join(",");
            });
          }
          var item = "";
          form.on("submit(gradeDeterminationSubmit)", function (data) {
            var field = data.field; //获取提交的字段
            let projectType = $("input[name='projectType']:checked").val();
            getCheck();
            item = {
              projectId: uuid,
              projectType: projectType,
              lineType: lineValue,
              stationFlag: flagValue,
              stationArea: areaValue,
              level: levelData,
              greenProject: greenProject,
              f: dataF,
            };
            $.ajax({
              type: "post",
              async: false, //异步执行
              // url: 'http://192.168.18.88:7071/outlineProjects/genData',
              url: base_url + "/outlineProjects/genData",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              dataType: "json",
              data: JSON.stringify(item),
              success: function (data) {
                if (data.code === "200") {
                  $(".gradeDeterminationSubmitHref")
                    .attr("lay-href", "./pages/guardianshipProgram.html")
                    .click();
                } else {
                  layer.msg("请进行等级计算！");
                }
              },
            });
            return false;
          });
          form.on("submit(gradeCalculationSubmit)", function (data) {
            gradeCalculationFun();
          });
          function gradeCalculationFun() {
            let projectType = $("input[name='projectType']:checked").val();
            // let lineType = $("input[name='lineType']:checked").val();
            // let stationFlag = $("input[name='stationFlag']:checked").val();
            // let stationArea = $("input[name='stationArea']:checked").val();
            getCheck();
            var arr_box = [];
            let adjustLevel = 0;
            let paras = [];
            $("input[name=soilMonitor]:checked").each(function () {
              arr_box.push($(this).val());
            });
            arr_box.forEach((item) => {
              adjustLevel = adjustLevel + Number(item);
            });

            for (let i in datas) {
              let item = {
                projectId: uuid,
                projectType: projectType,
                lineType: lineValue,
                stationFlag: flagValue,
                stationArea: areaValue,
                adjustLevel: adjustLevel,
              };
              item["projectSubType"] = i;
              for (let j = 0; j < datas[i].length; j++) {
                item[datas[i][j].field] = $("#" + i + datas[i][j].field).val();
              }
              paras.push(item);
            }

            $.ajax({
              type: "post",
              async: false, //异步执行
              // url: 'http://192.168.18.88:7071/outlineProjects/calcLevel',
              url: base_url + "/outlineProjects/calcLevel",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              dataType: "json",
              data: JSON.stringify(paras),
              success: function (data) {
                if (data.type == "success") {
                  levelData = data.data.level;
                  dataF = data.data.f;
                  var guardianshipLevel = $("input[name='level']");
                  guardianshipLevel.each(function (index, item) {
                    if (item.value == levelData) {
                      item.checked = true;
                    } else {
                      item.checked = false;
                    }
                    form.render();
                  });

                  layer.msg(data.message, { icon: 6 });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          }
          $(".backPreviousPage").on("click", function () {
            $(this).attr("lay-href", "./pages/technicalReview.html");
          });
        });
    </script>
  </body>
</html>
